package com.ruoyi.web.controller.consume;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consume.domain.GreenhousefilmApplyCon;
import com.ruoyi.consume.service.IGreenhousefilmApplyConService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 棚膜领用Controller
 *
 * @author ruoyi
 * @date 2021-07-23
 */
@Api("棚膜领用")
@RestController
@RequestMapping("/consume/greenhousefilmap")
public class GreenhousefilmApplyConController extends BaseController
{
    @Autowired
    private IGreenhousefilmApplyConService greenhousefilmApplyService;

    /**
     * 查询棚膜领用列表
     */
    @ApiOperation("查询棚膜领用列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmap:list')")
    @GetMapping("/list")
    public TableDataInfo list(GreenhousefilmApplyCon greenhousefilmApplyCon)
    {
        startPage();
        List<GreenhousefilmApplyCon> list = greenhousefilmApplyService.selectGreenhousefilmApplyList(greenhousefilmApplyCon);
        return getDataTable(list);
    }

    /**
     * 导出棚膜领用列表
     */
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmap:export')")
    @Log(title = "棚膜领用", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GreenhousefilmApplyCon greenhousefilmApplyCon)
    {
        List<GreenhousefilmApplyCon> list = greenhousefilmApplyService.selectGreenhousefilmApplyList(greenhousefilmApplyCon);
        ExcelUtil<GreenhousefilmApplyCon> util = new ExcelUtil<GreenhousefilmApplyCon>(GreenhousefilmApplyCon.class);
        return util.exportExcel(list, "棚膜领用数据");
    }

    /**
     * 获取棚膜领用详细信息
     */
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmap:query')")
    @GetMapping(value = "/{greenhousefilmApplyId}")
    public AjaxResult getInfo(@PathVariable("greenhousefilmApplyId") Long greenhousefilmApplyId)
    {
        return AjaxResult.success(greenhousefilmApplyService.selectGreenhousefilmApplyById(greenhousefilmApplyId));
    }

    /**
     * 新增棚膜领用
     */
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmap:add')")
    @Log(title = "棚膜领用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GreenhousefilmApplyCon greenhousefilmApplyCon)
    {
        return toAjax(greenhousefilmApplyService.insertGreenhousefilmApply(greenhousefilmApplyCon));
    }

    /**
     * 修改棚膜领用
     */
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmap:edit')")
    @Log(title = "棚膜领用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GreenhousefilmApplyCon greenhousefilmApplyCon)
    {
        return toAjax(greenhousefilmApplyService.updateGreenhousefilmApply(greenhousefilmApplyCon));
    }

    /**
     * 删除棚膜领用
     */
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmap:remove')")
    @Log(title = "棚膜领用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{greenhousefilmApplyIds}")
    public AjaxResult remove(@PathVariable Long[] greenhousefilmApplyIds)
    {
        return toAjax(greenhousefilmApplyService.deleteGreenhousefilmApplyByIds(greenhousefilmApplyIds));
    }

    /**
     * 更新库存量表
     */
    @ApiOperation("更新库存量表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmap:amount')")
    @Log(title = "棚膜领用", businessType = BusinessType.UPDATE)
    @PutMapping("/amount")
    public AjaxResult amount(@RequestBody GreenhousefilmApplyCon greenhousefilmApplyCon)
    {
        return toAjax(greenhousefilmApplyService.updateGreenhousefilmAmount(greenhousefilmApplyCon));
    }

    /**
     * 更新领用状态
     */
    @ApiOperation("更新领用状态")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmap:consu')")
    @Log(title = "棚膜领用", businessType = BusinessType.UPDATE)
    @PutMapping("/consu/{greenhousefilmApplyId}")
    public AjaxResult consume(@PathVariable("greenhousefilmApplyId") Long greenhousefilmApplyId)
    {
        return toAjax(greenhousefilmApplyService.updateConsumeStatus(greenhousefilmApplyId));
    }

    /**
     * 退回操作
     */
    @ApiOperation("退回操作")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmap:back')")
    @Log(title = "棚膜领用", businessType = BusinessType.UPDATE)
    @PutMapping("/back/{greenhousefilmApplyId}")
    public AjaxResult back(@PathVariable("greenhousefilmApplyId") Long greenhousefilmApplyId)
    {
        return toAjax(greenhousefilmApplyService.updateApprovalStatus(greenhousefilmApplyId));
    }
}
